﻿using ApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 节点版本配置
    /// </summary>
    internal class VerConfigController : HttpApiGateway.ApiController
    {
        private readonly IVerConfigService _Service;

        public VerConfigController(IVerConfigService service)
        {
            this._Service = service;
        }
        /// <summary>
        /// 添加节点版本
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public long Add(VerConfigDatum add)
        {
            return this._Service.Add(add);
        }
        /// <summary>
        /// 复制节点版本配置
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public long Copy(CopyVerParam param)
        {
            return this._Service.Copy(param.Id, param.Ver);
        }
        /// <summary>
        /// 删除节点版本配置
        /// </summary>
        /// <param name="id"></param>
        public void Delete([NumValidate("rpc.ver.id.null", 1)] long id)
        {
            this._Service.Delete(id);
        }
        /// <summary>
        /// 获取节点版本配置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ServiceVerConfig Get(long id)
        {
            return this._Service.Get(id);
        }
        /// <summary>
        /// 查询节点版本配置
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public PagingResult<BasicVerConfig> Query(PagingParam<VerQueryParam> query)
        {
            BasicVerConfig[] list = this._Service.Query(query.Param, query.ToBasicPaging(), out long count);
            return new PagingResult<BasicVerConfig>(list, count);
        }
        /// <summary>
        /// 修改节点版本配置
        /// </summary>
        /// <param name="set"></param>
        public void Set(LongParam<ServiceVerSet> set)
        {
            this._Service.Set(set.Id, set.Param);
        }
        /// <summary>
        /// 禁用或启用版本配置
        /// </summary>
        /// <param name="param"></param>
        public void SetIsEnable(LongParam<bool> param)
        {
            this._Service.SetIsEnable(param.Id, param.Param);
        }
    }
}
